package com.itheima.service.impl;

import com.itheima.dao.QrtzSchedulerStateDao;
import com.itheima.pojo.QrtzSchedulerState;
import com.itheima.service.QrtzSchedulerStateService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (QrtzSchedulerState)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:52
 */
@Service("qrtzSchedulerStateService")
public class QrtzSchedulerStateServiceImpl implements QrtzSchedulerStateService {
    @Resource
    private QrtzSchedulerStateDao qrtzSchedulerStateDao;

    /**
     * 通过ID查询单条数据
     *
     * @param schedName 主键
     * @return 实例对象
     */
    @Override
    public QrtzSchedulerState queryById(String schedName) {
        return this.qrtzSchedulerStateDao.queryById(schedName);
    }

    /**
     * 分页查询
     *
     * @param qrtzSchedulerState 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<QrtzSchedulerState> queryByPage(QrtzSchedulerState qrtzSchedulerState, PageRequest pageRequest) {
        long total = this.qrtzSchedulerStateDao.count(qrtzSchedulerState);
        return new PageImpl<>(this.qrtzSchedulerStateDao.queryAllByLimit(qrtzSchedulerState, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param qrtzSchedulerState 实例对象
     * @return 实例对象
     */
    @Override
    public QrtzSchedulerState insert(QrtzSchedulerState qrtzSchedulerState) {
        this.qrtzSchedulerStateDao.insert(qrtzSchedulerState);
        return qrtzSchedulerState;
    }

    /**
     * 修改数据
     *
     * @param qrtzSchedulerState 实例对象
     * @return 实例对象
     */
    @Override
    public QrtzSchedulerState update(QrtzSchedulerState qrtzSchedulerState) {
        this.qrtzSchedulerStateDao.update(qrtzSchedulerState);
        return this.queryById(qrtzSchedulerState.getSchedName());
    }

    /**
     * 通过主键删除数据
     *
     * @param schedName 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String schedName) {
        return this.qrtzSchedulerStateDao.deleteById(schedName) > 0;
    }
}
